# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2)

#set(CMAKE_CXX_FLAGS "-error-limit=0")

project("simpleplayer")

set(CMAKE_C_STANDARD 99)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ffmpeg/include/)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/module/include/)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/base/include/)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/module/demux/include/)

set(CORE_SOURCE MediaPlayer.cpp
        MediaPlayerjni.cpp)

set(PLATFROME
        ${CMAKE_CURRENT_SOURCE_DIR}/base/os/android/thread.c)

set(BASE_SOURCE
        ${CMAKE_CURRENT_SOURCE_DIR}/base/Looper.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/base/VideoDecoder.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/base/VideoRender.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/base/BaseStream.cpp
        module/demux/NDKDemux.cpp
        module/demux/FFMPEGDemux.cpp
        module/demux/mp4/Mp4Demux.cpp
        module/demux/mkv/MkvDemux.cpp
        module/demux/mkv/MKVNodeBase.cpp
        module/demux/ts/TsDemux.cpp
        module/demux/ts/TsFilter.cpp
        module/datasource/FileDatasource.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/module/NDKDecoder.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/module/NDKRender.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/base/Demux.cpp)

set(PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ffmpeg/lib)
add_library(ffmpeg_libavcodec
        SHARED
        IMPORTED)
set_target_properties(ffmpeg_libavcodec
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libavcodec.so)

add_library(ffmpeg_libavdevice
        SHARED
        IMPORTED)

set_target_properties(ffmpeg_libavdevice
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libavdevice.so)

add_library(ffmpeg_libavfilter
        SHARED
        IMPORTED)
set_target_properties(ffmpeg_libavfilter
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libavfilter.so)

add_library(ffmpeg_libavformat
        SHARED
        IMPORTED)

set_target_properties(ffmpeg_libavformat
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libavformat.so)

add_library(ffmpeg_libavutil
        SHARED
        IMPORTED)
set_target_properties(ffmpeg_libavutil
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libavutil.so)


add_library(ffmpeg_libswresample
        SHARED
        IMPORTED)
set_target_properties(ffmpeg_libswresample
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libswresample.so)

add_library(ffmpeg_libswscale
        SHARED
        IMPORTED)
set_target_properties(ffmpeg_libswscale
        PROPERTIES IMPORTED_LOCATION
        ${PATH}/${ANDROID_ABI}/libswscale.so)

add_library( # Sets the name of the library.
        mymediaplayer

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        ${CORE_SOURCE} ${BASE_SOURCE} ${PLATFROME})

#add_subdirectory(ref)
#add_subdirectory(module)
#add_subdirectory(componet)

#find_library(componet-lib
#        compont)



target_link_libraries( # Specifies the target library.
        mymediaplayer

        log

        ffmpeg_libavcodec
        ffmpeg_libavdevice
        ffmpeg_libavfilter
        ffmpeg_libavformat
        ffmpeg_libavutil
        ffmpeg_libswresample
        ffmpeg_libswscale
        android
        mediandk
        OpenMAXAL)